<?php
	
	require 'configDB.php';

	$id_matpel = array();
	
	$kelas = $_POST['kelas'];
	$jurusan = $_POST['jurusan'];
	$no_kelas = $_POST['no_kelas'];
	$id_guru = $_POST['id_guru'];
	$id_matpel = $_POST['id_matpel'];

	//Kelas k
	//Jadwal Pelajaran jp
	//Penugasan Guru pg
	//Mata Pelajaran mp

	$query_str = "SELECT mp.nama , mp.id FROM kelas k, jadwal_pelajaran jp, penugasan_guru pg, mata_pelajaran mp WHERE k.tingkat='$kelas' AND k.id=jp.id_kelas AND jp.id_penugasan=pg.id AND pg.id_matpel=mp.id AND k.id_jurusan='$jurusan' AND k.nomor='$no_kelas' ";
	if ($id_guru != "") {
		$query_str .= " AND pg.NIK='$id_guru'";
	}
	$query = mysql_query($query_str);
	
	/*$kelas_query = mysql_query("SELECT * FROM kelas WHERE tingkat='$kelas' AND id_jurusan='$jurusan'");
	//echo "SELECT * FROM kelas WHERE tingkat='$kelas' AND id_jurusan='$jurusan'\n";
	while ($kelas_data = mysql_fetch_assoc($kelas_query)) {
		$id_kelas = $kelas_data['id'];
		$jadwal = mysql_query("SELECT * FROM jadwal_pelajaran WHERE id_kelas='$id_kelas'");
		//echo "SELECT * FROM jadwal_pelajaran WHERE id_kelas='$id_kelas'\n";
		while ($jadwal_data = mysql_fetch_assoc($jadwal)) {
			$id_penugasan = $jadwal_data['id_penugasan'];
			$guru_command = ($id_guru == "") ? "" : " AND NIK='$id_guru'";
			$penugasan = mysql_query("SELECT * FROM penugasan_guru WHERE id='$id_penugasan'" . $guru_command);
			//echo "SELECT * FROM penugasan_guru WHERE id='$id_penugasan'" . $guru_command . "\n";
			while ($penugasan_data = mysql_fetch_assoc($penugasan)) {
				$id_matpel = $penugasan_data['id_matpel'];
				$matpel = mysql_query("SELECT * FROM mata_pelajaran WHERE id='$id_matpel'");
				$matpel_data = mysql_fetch_assoc($matpel);
				$id_matpel[] = $id_matpel . "+" . $matpel_data['nama'];
			}
		}
	}

	foreach ($id_matpel as $id) {
		echo $id . "-";
	}*/
	while($data = mysql_fetch_array($query))
	{
		$selected = ($id_matpel == $data['id']) ? " selected" : "";
		echo '<option value="'.$data['id'].'"'.$selected.'>'.$data['nama'].'</option>';
	}
	//echo "123123+Bahasa Indonesia-1231235+ASDFG-6677+IUYURWE-";

	//$query = mysql_query("DELETE FROM kode_pos WHERE kode_pos='$id'");
	
	//header("Location: ../laporan_data_kodePos.php");
?>